import { listChat,fakeAnswerRecordsData, fakeAnswerRelevanceData,fakeAnswerRelevanceUpDownData,fakeAnswerRelevanceknowledgeData } from '@/services/datastatistics';

export default {
  namespace: 'answerRecords', // model的名字 用来在页面中找到要调用的那一个model

  state: {
    list:[],
    suggestList: [],
    qaList: [],
  },

  effects: {
    *fetch({ payload, callback }, { call, put }) {
      const response = yield call(fakeAnswerRecordsData, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *listChat({ payload, callback }, { call, put }) {
      const response = yield call(listChat, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *fetchb({payload,callback},{call,put}){
      const responses = yield call(fakeAnswerRelevanceData,payload);
      if (responses) {
        if (callback && typeof callback === 'function') {
          callback(responses);
        }
        yield put({
          type: 'saves',
          payload: responses,
        });
      }
    },
    *fetchc({payload,callback},{call,put}){
      const responseA = yield call(fakeAnswerRelevanceUpDownData,payload);
      if (responseA) {
        if (callback && typeof callback === 'function') {
          callback(responseA);
        }
        yield put({
          type: 'saveA',
          payload: responseA,
        });
      }
    },
    *fetchd({payload,callback},{call,put}){
      const responseB = yield call(fakeAnswerRelevanceknowledgeData,payload);
      if (responseB) {
        if (callback && typeof callback === 'function') {
          callback(responseB);
        }
        yield put({
          type: 'saveB',
          payload: responseB,
        });
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state, 
        ...payload,
      };
    },
    fetchb(state,{payload}){
      return {
        ...state,
        ...payload,
      };
    },
    fetchc(state,{payload}){
      return {
        ...state,
        ...payload,
      };
    },
    fetchd(state,{payload}){
      return {
        ...state,
        ...payload,
      };
    },
    clear() {
      return {
        list:[],
        suggestList: [],
        qaList: [],
      };
    },
  },
};
